package _11_整理题目._1_链表指针._翻转链表;

import org.junit.Test;
import util.ListNode;

/**
 * 翻转链表
 */

public class _01_反转链表 {
    
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode nex = cur.next;
            cur.next = pre;
            pre = cur;
            cur = nex;
        }
        return pre;
    }


    
    @Test
    public void main() {
        Integer[] array = {1,2,3,4,5};
        ListNode head = ListNode.getListFromArray(array);
        ListNode.printList(head);
        ListNode result = reverseList(head);
        ListNode.printList(result);
    }
}
